package se.jocke.nbrs.model;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author jocke
 */
public class NameValueTableModel extends AbstractTableModel {

    private static final long serialVersionUID = 1L;

    private final Map<String, String> data = new LinkedHashMap<String, String>();

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Entry[] array = (Entry[]) data.entrySet().toArray();

        if (columnIndex == 0) {
            return array[rowIndex].getKey();

        } else {
            return array[rowIndex].getValue();
        }
    }

    public Map<String, String> getData() {
        return Collections.unmodifiableMap(data);
    }
}
